package com.qqhh;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Main {
    public static void main(String[] args) {
//        Stream<Integer> stream = Stream.of(11,1, 2, 2, 3, 3, 3,7,8,19);
//        Stream<Integer> abc = stream.distinct()//去重
//                .sorted()//排序，从小到大
//                .filter(n -> n % 2 != 0)//过滤出奇数
//                .skip(2)//跳过前2个
//                .limit(3);//截断，保留前三
//        abc.forEach(System.out::println);
//        abc.collect(Collectors.toList());//异常
//        Optional<Integer> reduce = abc.reduce((a, b) -> a + b);
//        System.out.println(reduce);

//        List<Integer> list= Arrays.asList(1,3,4,5,5,5,5,7,8);
//        List<Integer> collect = list.stream().collect(Collectors.toList());
//        collect.stream().forEach(System.out::println);
//        Optional<Integer> reduce1 = collect.stream().reduce((a, b) -> a + b);
//        System.out.println(reduce1);
//


        Stream<String> stream2 = Stream.of("apple", "banana", "cherry");
        Stream<String> mappedStream = stream2.map(String::toUpperCase); // 映射为单词长度
        mappedStream.forEach(System.out::println);

//        List<List<Integer>> nestedList = Arrays.asList(
//                Arrays.asList(1, 2),
//                Arrays.asList(3, 4),
//                Arrays.asList(5, 6)
//        );
//        Stream<Integer> flattenedStream = nestedList.stream().flatMap(List::stream); // 扁平化为一个流
//        flattenedStream.forEach(System.out::println);
    }

}
